package com.xmy.cultivate.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xmy.cultivate.entity.FincDisburse;
import com.xmy.cultivate.entity.Organization;
import com.xmy.cultivate.entity.OrganizationDepartmentPrincipal;
import com.xmy.cultivate.mapper.FincDisburseMapper;
import com.xmy.cultivate.service.IDepartmentService;
import com.xmy.cultivate.service.IFincDisburseService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xmy.cultivate.service.IOrganizationService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 支出表 服务实现类
 * </p>
 *
 * @author hpiggy
 * @since 2025-05-17
 */
@Service
public class FincDisburseServiceImpl extends ServiceImpl<FincDisburseMapper, FincDisburse> implements IFincDisburseService {
    @Autowired
    FincDisburseMapper fincDisburseMapper;

    @Autowired
    @Lazy
    IOrganizationService iOrganizationService;
    @Autowired
    @Lazy
    IDepartmentService iDepartmentService;



    public IPage<FincDisburse> findAll(IPage<FincDisburse> page, String yearPart, String quarterNum, String handleName, String fincTypeId,String fincTypeSubId, String schoolOrDepartmentId,String startDate, String endDate) {

        String type =" 1";  //1:校区 2:部门
        Organization organization = iOrganizationService.getById(schoolOrDepartmentId);
        if (organization == null){
            type = "2";
        }
        return fincDisburseMapper.findAll(page, yearPart, quarterNum,  handleName, fincTypeId,fincTypeSubId, schoolOrDepartmentId,startDate, endDate,type);
    }

    public List<Map<String, Object>> getSchoolAndDepart(){
        return fincDisburseMapper.getSchoolAndDepart();
    }
    public boolean updateFincDisburseInfo( Long schoolId,
                                    Long departmentId,
                                    Long fincTypeId,
                                    Long fincTypeSubId,
                                    Long handleId,
                                    String handleDate,
                                    BigDecimal disbursePrice,
                                    String disburseDetail,
                                    String remark,
                                    Long adminId,
                                    Long id){
        return fincDisburseMapper.updateFincDisburseInfo( schoolId,departmentId,  fincTypeId, fincTypeSubId, handleId, handleDate, disbursePrice, disburseDetail, remark,adminId, id);
    }

    public IPage<FincDisburse> fincDisburseCount(IPage<FincDisburse> page, String yearPart, String quarterNum, String fincTypeId,String fincTypeSubId, String startDate, String endDate) {

        return fincDisburseMapper.fincDisburseCount(page, yearPart, quarterNum, fincTypeId,fincTypeSubId,startDate, endDate);
    }


    public List<FincDisburse> getFincDisburse(String yearPart, String quarterNum, String fincTypeId,String fincTypeSubId, String startDate, String endDate) {

        return fincDisburseMapper.getFincDisburse( yearPart, quarterNum, fincTypeId,fincTypeSubId,startDate, endDate);
    }

    public List<FincDisburse> getFincDisburseFindAll(String yearPart, String quarterNum, String fincTypeId,String fincTypeSubId, String startDate, String endDate) {

        return fincDisburseMapper.getFincDisburseFindAll( yearPart, quarterNum, fincTypeId,fincTypeSubId,startDate, endDate);
    }

}
